package com.ling.util;

import com.zhenzi.sms.ZhenziSmsClient;

public class SmsZhenZiUtil {
    private static final String apiUrl = "https://sms_developer.zhenzikj.com/";
    private static final String appId = "101035";
    private static final String appSecret = "eab08a15-de63-4eef-9115-95d20de39897";

    /**
     * 发送短信
     * @return 是否发送成功
     */
    public static boolean sendSMS(String tel,String code) {
        //发送短信
        ZhenziSmsClient client = new ZhenziSmsClient(apiUrl, appId, appSecret);
        try {
            String send = client.send(tel, "尊敬的用户，您的验证码"+code+"，该验证码5分钟内有效，请勿泄漏于他人！");
            String[] split = send.split(",");
            if ("0".equals(split[0].substring(split[0].lastIndexOf(":") + 1))) {
                return true;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;
    }

    public static void main(String[] args) {
        if (sendSMS("15797656200", "123456")) {
            System.out.println("发送成功！");
        }
    }
}
